home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 December / PCWorld_2004-12_cd.bin / software / temacd / tiny / tf6pro-6[1].0.140.exe / Tiny Firewall Pro 6.0.msi / ws_except.js < prev    next >
Encoding:
JavaScript  |  2004-07-20  |  14.1 KB  |  498 lines

  1. /*//////////////////////////////////////////////////////////////////////
  2. filename:         ws_except.js
  3. copyright(c):     2002, 2003 Tiny Software Inc (http://www.tinysoftware.com)
  4. author:         Martin Navratil (mnavratil@tinysoftware.com)
  5. product:         Tiny Firewall Pro 6.x, Policy Editor
  6. description:     javascript functions for ws_except.html
  7. ///////////////////////////////////////////////////////////////////////*/
  8. var    ERR_GET_MODULE_PARSER = "Error: Cannot get Parser object for Sandbox ",
  9.      HTML_TABLE_HEADER = '<table width="100%" border="1" cellpadding=0 cellspacing=0 bordercolor="#000000">',
  10.     HTML_TABLE_TRAILER = "</table>",
  11.     HTML_TABLE_LABEL_HEADER1 = "<table width=100% border=0 cellspacing=0 cellpadding=0><tr bgcolor=",
  12.     HTML_TABLE_LABEL_HEADER2 = "><td height=25 align=middle><font color=black><B>",
  13.     HTML_TABLE_LABEL_TRAILER = "</B></font></td></tr></table>",
  14.     HTML_ROW_HEADER = "<TR>",
  15.     HTML_ROW_TRAILER = "</TR>",
  16.     HTML_HEADER_HEADER = '<th class="tdclass" style="font-face:bold; font-size:8pt;">',
  17.     HTML_LASTHEADER_HEADER = '<th colspan=2 align=left class="tdclass" style="font-face:bold; font-size:8pt;">',
  18.     HTML_HEADER_TRAILER = "</th>",
  19.     HTML_CELL_HEADER = "<TD align=center class=tdclass>",
  20.     HTML_CELL_TRAILER = "</TD>",
  21.     HTML_ID_LINK_HEADER = '<A href=# onclick=\'',
  22.     HTML_ID_LINK_TRAILER = '</A>',
  23.     HTML_INSERT_USER_EXCEPTION = '<IMG src="ico-plus.gif" align=absMiddle alt = "Exception for non-system processes"/>  Exception for non-system processes',
  24.     HTML_INSERT_SYSTEM_EXCEPTION = '<IMG src="ico-plus.gif" align=absMiddle alt = "Exception for system processes"/>  Exception for system processes',
  25.     HTML_ADD_EXISTING = '<IMG src="ico-plus.gif" align=absMiddle alt = "Add existing exception"/>  Add existing exception',
  26.     HTML_ICO_MINUS = '<IMG src="ico-minus.gif" alt="Delete exception"/>',
  27.     HTML_SELECT_HEADER = '<SELECT ',
  28.     HTML_SELECT_TRAILER = '></SELECT>',
  29.     HTML_EDIT_HEADER = '<INPUT type=edit ',
  30.     HTML_EDIT_TRAILER = '</INPUT>',
  31.     HTML_DISABLED = 'disabled';
  32.  
  33. var NO_GUARDS = 7;
  34. var    NO_COLUMNS = NO_GUARDS + 2;
  35.  
  36.  
  37. var RA_USER    = 0,
  38.     RA_SYSTEM = RA_USER + 1,
  39.     RA_BOTH    = RA_SYSTEM + 1;
  40.  
  41. var    TXT_PRO_HIGH_MASTER = "Common exceptions",
  42.     TXT_CLIENT = "Medium Priority List - Non-Privileged user Defined",
  43.     TXT_PRO_LOW_MASTER = "Low Priority List - Common exceptions",
  44.     TXT_DELETING = "Deleting exception",
  45.     TXT_QST_REALLYDELETE1 = 'Do you really want to delete ',
  46.     TXT_QST_REALLYDELETE2 = ' from the list of active guards?',
  47.     TXT_NEW_EXC_APP = 'Enter app./group',
  48.     
  49. // columns
  50.     TXT_APP_CAPTION = "Guards active for the application or group",
  51.     TXT_FIL_CAPTION = "File",
  52.     TXT_SRV_GUARD = "Services Control",
  53.     TXT_REG_GUARD = "Registry",
  54.     TXT_SPW_GUARD = "Application Spawning",
  55.     TXT_DLL_GUARD = "DLL Loading",
  56. //    TXT_DEV_GUARD = "Device",
  57.     TXT_VBA_GUARD = "VBA macro",
  58.     TXT_COM_GUARD = "OLE/COM Control",
  59.     TXT_SPR_GUARD = "System privileges",
  60.     TXT_DPR_GUARD = "Device privilege",
  61.     TXT_ASSIGNMENT = (iManaged||iContext ? "Assignment" : "Users");
  62.     TXT_ALLUSERS = "All Users (*)",
  63.     TXT_APPALL_USER = "All(*)",
  64.     TXT_APPALL_SYSTEM = "System All(*)";
  65.  
  66. var    GUARD_FILE = 0x00000001,
  67.     GUARD_SERVICE = 0x00000002,
  68.     GUARD_REGISTRY = 0x00000004,
  69.     GUARD_SPAWNING = 0x00000008,
  70.     GUARD_DEVICE = 0x00000010,
  71.     GUARD_VBAMACRO = 0x00000020,
  72.     GUARD_COMOBJECT = 0x00000040,
  73.     GUARD_SYSTEMPRIV = 0x00000080,
  74.     GUARD_DEVICEPRIV = 0x00000100,
  75.     GUARD_DLL = 0x00020000,
  76.     GUARD_ALL = GUARD_FILE + GUARD_SERVICE + GUARD_REGISTRY + GUARD_SPAWNING + GUARD_COMOBJECT + GUARD_SYSTEMPRIV + GUARD_DLL;
  77.  
  78. var arrGuards = new Array( 
  79.     GUARD_FILE,
  80.     GUARD_REGISTRY,
  81.     GUARD_SPAWNING,
  82.     GUARD_DLL,
  83.     GUARD_COMOBJECT,
  84.     GUARD_SERVICE,
  85.     GUARD_SYSTEMPRIV);
  86.     
  87.     
  88. var     PRIOR_LOW = 0,
  89.     PRIOR_NORMAL = 1,
  90.     PRIOR_HIGH = 2;
  91.  
  92. var arrLinksApp = new Array();
  93. var iLastIndex = -1;
  94.  
  95. var strAsgnmt = "";
  96.  
  97. var    enter_pressed = 0;
  98.  
  99. var     strHeaders = new Array(NO_COLUMNS),
  100.     strDisabled = new Array(3);
  101.  
  102. strHeaders[0] = TXT_APP_CAPTION;
  103. strHeaders[1] = TXT_FIL_CAPTION;
  104. strHeaders[2] = TXT_REG_GUARD;
  105. strHeaders[3] = TXT_SPW_GUARD;
  106. strHeaders[4] = TXT_DLL_GUARD;
  107. strHeaders[5] = TXT_COM_GUARD;
  108. strHeaders[6] = TXT_SRV_GUARD;
  109. strHeaders[7] = TXT_SPR_GUARD;
  110. strHeaders[8] = TXT_ASSIGNMENT;
  111. strHeaders[9] = "";
  112.  
  113. var     arrExcept = new Array(),
  114.     arrLabelTypes = new Array(),
  115.     arrExceptIndex = 0;
  116.  
  117. var ServerParser, ClientParser, ServerAppParser, ClientAppParser;
  118.     var iProductType = window.external.ProductType;
  119.     
  120. //function SetAssignment(str)
  121. //{
  122. //    strAsgnmt = str;
  123. //    _excList.innerHTML = GetExceptionList();
  124. //}
  125.  
  126. function GetExceptionList()
  127. {
  128.     var Option, OptList, strExcepts;
  129.     strExcepts = "";
  130.  
  131.     strDisabled[PRIOR_HIGH] = "";
  132.     strDisabled[PRIOR_LOW] = "";
  133.     if ((iContext == 0 && iManaged == 1) || !bIsAdmin)
  134.     {
  135.         strDisabled[PRIOR_HIGH] = HTML_DISABLED;
  136.         strDisabled[PRIOR_LOW] = HTML_DISABLED;
  137.     }
  138.     else
  139.     {
  140.         strDisabled[PRIOR_HIGH] = '';
  141.         strDisabled[PRIOR_LOW] = '';
  142.     }
  143.     strDisabled[PRIOR_NORMAL] = '';
  144.  
  145.     if (ServerParser != null)
  146.         strExcepts += GetExcListSingleParser(ServerParser, PRIOR_HIGH, "Server")  + "<BR/><BR/>";
  147.  
  148.     return strExcepts;
  149. }
  150.  
  151. function GetExcListSingleParser(Parser, prio, ParserName)
  152. {
  153.     var strRetVal = '<table width="400" border="0"><tr>';
  154.     strRetVal += '<td width=200><A href="#" style="color: Black; text-decoration: none;" ' + strDisabled[prio] + ' ';
  155.     if (strDisabled[prio] == '')
  156.         strRetVal += 'onclick="OnAdd(' + prio + ', ' + RA_USER + ')"';
  157.     strRetVal += '>' + HTML_INSERT_USER_EXCEPTION + '</A></td>';
  158.     strRetVal += '<td width=200><A href="#" style="color: Black; text-decoration: none;" ' + strDisabled[prio] + ' ';
  159.     if (strDisabled[prio] == '')
  160.         strRetVal += 'onclick="OnAdd(' + prio + ', ' + RA_SYSTEM + ')"';
  161.     strRetVal += '>' + HTML_INSERT_SYSTEM_EXCEPTION + '</A></td>';
  162.     if (iContext == 1)
  163.     {
  164.         strRetVal += '<td><A href="#" style="color: Black; text-decoration: none;" ';
  165.         if (strDisabled[prio] == "")
  166.             strRetVal += 'onclick="ShowAddExceptDlg()"';
  167.         strRetVal += strDisabled[prio] + '>' + HTML_ADD_EXISTING + '</A></td></tr></table>';
  168.     }
  169.     else
  170.         strRetVal += '</tr></table>';
  171.  
  172.     strRetVal += HTML_TABLE_HEADER;
  173.     if (Parser == null)
  174.     {
  175.         strRetVal = ERR_GET_MODULE_PARSER + "(" + ParserName + ")";
  176.         return strRetVal;
  177.     }
  178.     strRetVal += HTML_ROW_HEADER;
  179.     var i;
  180.  
  181.     if (iManaged == 0 /* Home Version  */ && prio != PRIOR_NORMAL ||
  182.         iManaged == 1 && iContext == 1 /* BBE */)
  183.         
  184.         for (i = 0; i < NO_COLUMNS; i++)
  185.         {
  186. // last column has span==2
  187.             if (i < NO_COLUMNS)
  188.                 strRetVal += HTML_HEADER_HEADER + strHeaders[i] + HTML_HEADER_TRAILER;
  189.             else
  190.                 strRetVal += HTML_LASTHEADER_HEADER + strHeaders[i] + HTML_HEADER_TRAILER;
  191.         }
  192.     else
  193.         for (i = 0; i < NO_COLUMNS - 1; i++)
  194.         {
  195.             if (i < NO_COLUMNS - 2)
  196.                 strRetVal += HTML_HEADER_HEADER + strHeaders[i] + HTML_HEADER_TRAILER;
  197.             else
  198.                 strRetVal += HTML_LASTHEADER_HEADER + strHeaders[i] + HTML_HEADER_TRAILER;
  199.         }
  200.     
  201.     strRetVal += HTML_ROW_TRAILER;
  202.     ExcList = new Enumerator(Parser.AppExceptionList);
  203.     ExcList.moveFirst();
  204.     i = arrExcept.length;
  205.        while (!ExcList.atEnd())
  206.        {
  207.         //add option to array
  208.         var except = ExcList.item();
  209.         if (except.Priority == prio)
  210.         {
  211.             arrExcept[i++] = except;
  212.             strRetVal += GetExceptStr(except, prio, arrExceptIndex++);
  213.         }
  214.           ExcList.moveNext();                 //Get next exception
  215.        }
  216.     strRetVal += HTML_TABLE_TRAILER;
  217.     return strRetVal;
  218. }
  219.  
  220. function GetExceptStr(appExcept, prio, index)
  221. {
  222.     var strApp = HTML_ROW_HEADER;
  223.     var strAppName = appExcept.Application;
  224.     var excAsgnmt = appExcept.Assignment;
  225.  
  226.     if (strAppName == '*')
  227.     {
  228.         if (RA_USER == appExcept.Account)
  229.             strAppName = TXT_APPALL_USER;
  230.         else
  231.             strAppName = TXT_APPALL_SYSTEM;
  232.     }
  233.  
  234. //filter by assignemnt
  235.     switch (iContext)
  236.     {
  237.     case 0:
  238.         excAsgnmt = excAsgnmt.toLowerCase( );
  239.         if (excAsgnmt != "*" && strAsgnmt != TXT_ALLUSERS && 
  240.                 excAsgnmt.indexOf(strAsgnmt.toLowerCase( )) == -1)
  241.         {
  242.             return "";
  243.         }
  244.         break;
  245.     case 1:
  246.         if (!ctrlAsgnmt.CheckRule(excAsgnmt))
  247.         {
  248.             return "";
  249.         }
  250.         break;
  251.     }
  252.  
  253.     // adding some display about the System/User/Both accounts
  254.     var strSysFlag = "";
  255.     if (appExcept.Application != '*' && appExcept.AppType == AT_LABEL)
  256.     {
  257.         switch (appExcept.Account) {
  258.         case RA_USER: strSysFlag += "";
  259.             break;
  260.         case RA_SYSTEM:
  261.             strSysFlag += " $";
  262.             break;
  263.         case RA_BOTH: strSysFlag += " +$";
  264.             break;
  265.         }
  266.     }
  267.         
  268.     if (strAppName == '')
  269.     {
  270.         strApp += HTML_CELL_HEADER + 
  271.             GetLabelListHtmlStr(prio, appExcept.Account, 'SELECT_' + index, strAppName, index) + strSysFlag + HTML_CELL_TRAILER;
  272.         appExcept.Application = '*';
  273.     } else
  274.     {
  275.         strApp += HTML_CELL_HEADER;
  276.         var strLinkApp = HTML_ID_LINK_HEADER;
  277.         if (strDisabled[prio] == "")
  278.             strLinkApp += 'AppComboCleanup('+index+');this.outerHTML=GetLabelListHtmlStr(' + prio + ',' +  appExcept.Account + ', "SELECT_' + index + 
  279.                 '","' + strAppName + '",' + index +')\' ';
  280.         else
  281.             strLinkApp += '\' ';
  282.         strLinkApp += strDisabled[prio] + '>' + strAppName + HTML_ID_LINK_TRAILER;
  283.         arrLinksApp[index] = strLinkApp;
  284.         
  285.         strApp += strLinkApp + strSysFlag + HTML_CELL_TRAILER;
  286.     }
  287.  
  288.     var lGuards = appExcept.ActiveGuards;
  289.     for (j = 0; j < NO_GUARDS; j++)
  290.     {
  291. //    for (i = GUARD_FILE; i <= GUARD_DEVICEPRIV; i *= 2)
  292.         i = arrGuards[j];
  293. // VBA guard is currently disabled
  294.         if (GUARD_VBAMACRO == i || GUARD_DEVICE == i)
  295.             continue;
  296.         var strGuard = ((lGuards & i) > 0) ? " checked=1 " : "";
  297.         strApp += HTML_CELL_HEADER + "<INPUT type=checkbox " + strGuard + 'onclick="OnGuardChange(' + index + "," + i + ')" ' + strDisabled[prio] + "></INPUT>" + HTML_CELL_TRAILER;
  298.     }
  299.     if (iManaged == 0 /* Home Version  */ && prio != PRIOR_NORMAL ||
  300.         iManaged == 1 && iContext == 1 /* BBE */)
  301.     {
  302.         var strAsgnDisabled = strDisabled[prio];
  303.         if (iProductType == 1)
  304.             strAsgnDisabled = HTML_DISABLED;
  305.  
  306.         strApp += HTML_CELL_HEADER;
  307.         if (iManaged)
  308.         {
  309.             strApp += HTML_EDIT_HEADER + ' value="' + appExcept.Assignment + '"' + 
  310.             ' onchange="OnAsgnmtChange(' + index + ',this.value);" ' + strAsgnDisabled + HTML_EDIT_TRAILER;
  311.         } else
  312.         {
  313.             strApp += HTML_ID_LINK_HEADER;
  314.             if (strAsgnDisabled == '')
  315.                 strApp += 'OnUsersChange(' + index +'); \' ';
  316.             else
  317.                 strApp += '\' ';
  318.             strApp += strAsgnDisabled + '>' + appExcept.Assignment + HTML_ID_LINK_TRAILER;
  319.         }
  320.         strApp += HTML_CELL_TRAILER;
  321.  
  322. //        strApp += HTML_CELL_HEADER + HTML_EDIT_HEADER + 'onchange="OnAsgnmtChange(' + index + ',this.value);" value="';
  323. //        strApp += appExcept.Assignment + '" ' + strAsgnDisabled + '/>' + HTML_CELL_TRAILER;
  324.     }
  325.     strApp += HTML_CELL_HEADER + 
  326.         '<A href="#" ';
  327.     if (strDisabled[prio] == '')
  328.         strApp += 'onclick="OnDelete(' + prio + ',' + index + ')"';
  329.     strApp += '>' + HTML_ICO_MINUS + HTML_CELL_TRAILER + HTML_ROW_TRAILER;
  330.  
  331.     return strApp;
  332. }
  333.  
  334. function OnGuardChange(index, guard)
  335. {
  336.     try
  337.     {
  338.         var appExcept = arrExcept[index];
  339.         var mask = appExcept.ActiveGuards;
  340.         mask ^= guard;
  341.         appExcept.ActiveGuards = mask;
  342.     } catch(e)
  343.     {
  344.         alert("Access violation");
  345.     }
  346. }
  347.  
  348. function OnAdd(priority, account)
  349. {
  350.     var Parser;
  351.     switch (priority)
  352.     {
  353.     case PRIOR_HIGH:
  354.     case PRIOR_LOW:
  355.         Parser = ServerParser;
  356.         break;
  357.     case PRIOR_NORMAL:
  358.         Parser = ClientParser;
  359.     }
  360.  
  361.     try 
  362.     {
  363.         var excList = Parser.AppExceptionList;
  364.         var newExc = excList.CreateAppException();
  365.         newExc.Application = '';
  366.         newExc.Priority = priority;
  367.         newExc.Assignment = (iContext ? ctrlAsgnmt.Assignment : "*");
  368.         newExc.ActiveGuards = GUARD_ALL;
  369.         newExc.Account = account;
  370.         excList.Insert(newExc);
  371.     } catch (e)
  372.     {
  373.         alert("Access violation");
  374.     }
  375.     _excList.innerHTML = GetExceptionList();
  376. }
  377.  
  378. function AppComboCleanup(index)
  379. {
  380.     var iIndex = parseInt(index);
  381.     if (document.getElementById)
  382.     {
  383.         var combo = document.getElementById("SELECT_"+iLastIndex);
  384.         if (combo)
  385.         {
  386.             combo.outerHTML = arrLinksApp[iLastIndex];
  387.         }
  388.     }
  389.     iLastIndex = iIndex;
  390. }
  391.  
  392. function OnDelete(priority, index)
  393. {
  394.     var except = arrExcept[index];
  395.     var strNewAsgnmt = "";
  396.     var curStrAsgnmt = (iContext ? ctrlAsgnmt.Assignment : strAsgnmt);
  397.     if (iContext == 1 && !ctrlAsgnmt.IsEmptyOrAll(curStrAsgnmt))
  398.     {
  399.         strNewAsgnmt = ctrlAsgnmt.Remove(except.Assignment);
  400.         except.Assignment = strNewAsgnmt;
  401.     }
  402.     if (iContext == 0 || strNewAsgnmt == "")
  403.     {
  404.         var arg = new Array(2);
  405.         arg[0] = TXT_QST_REALLYDELETE1 + '"' + arrExcept[index].Application + '"' +
  406.             TXT_QST_REALLYDELETE2;
  407.         arg[1] = TXT_DELETING;
  408.         var answer=showModalDialog('question.html', arg, 'dialogWidth=300pt;dialogHeight=100pt;');
  409.         if (answer == 0)
  410.             return;
  411.  
  412.         var Parser;
  413.         switch (priority)
  414.         {
  415.         case PRIOR_HIGH:
  416.         case PRIOR_LOW:
  417.             Parser = ServerParser;
  418.             break;
  419.         case PRIOR_NORMAL:
  420.             Parser = ClientParser;
  421.         }
  422.  
  423.         try 
  424.         {
  425.             var excList = Parser.AppExceptionList;
  426.             excList.Remove(arrExcept[index]);
  427.         } catch (e)
  428.         {
  429.             alert("Access violation");
  430.         }
  431.     }
  432.     _excList.innerHTML = GetExceptionList();
  433. }
  434.  
  435. function OnAppChange(prio, elem, index, value)
  436. {
  437.     var i;
  438.     try 
  439.     {
  440.         arrExcept[index].Application = value;
  441.         arrExcept[index].AppType = arrLabelTypes[value];
  442.     } catch (e)
  443.     {
  444.         alert("Access violation");
  445.     }
  446.  
  447.     var strLinkApp = HTML_ID_LINK_HEADER;
  448.     if (strDisabled[prio] == "")
  449.         strLinkApp += 
  450.                 'AppComboCleanup('+index+');this.outerHTML=GetLabelListHtmlStr(' + prio + ',' + arrExcept[index].Account + ', "SELECT_' + index + 
  451.                 '","' + value + '",' + index +');\' ';
  452.     else
  453.         strLinkApp += '"" ';
  454.     strLinkApp += strDisabled[prio] + '>' + value + HTML_ID_LINK_TRAILER;
  455.     arrLinksApp[index] = strLinkApp;
  456.     elem.outerHTML = strLinkApp;
  457. }
  458.  
  459.  
  460. function OnAsgnmtChange(index, value)
  461. {
  462.     var appExcept = arrExcept[index];
  463.     try
  464.     {
  465.         appExcept.Assignment = value;    
  466.         _excList.innerHTML = GetExceptionList();
  467.     } catch (e)
  468.     {
  469.         alert("Access violation");
  470.     }
  471. }
  472.  
  473. function OnUsersChange(index)
  474. {
  475.     var appExcept = arrExcept[index];
  476.     var strNewUsers = showModalDialog('UsersDlg.html', new Array(appExcept.Assignment), 'dialogWidth=215pt;dialogHeight=200pt;');
  477.     try
  478.     {
  479.         appExcept.Assignment = strNewUsers;
  480.         _excList.innerHTML = GetExceptionList();
  481.     } catch (e)
  482.     {
  483.         alert("Access violation");
  484.     }
  485. }
  486.  
  487. function OnKeyDown()
  488. {
  489.     var k = window.event.keyCode;
  490.     if (13 == k)
  491.     {
  492.         enter_pressed = 1;
  493.         window.event.srcElement.click();
  494.     }
  495.     return k;
  496. }
  497.  
  498.